package edu.gdut.tiantian.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import edu.gdut.tiantian.entity.OrderItem;

@Repository
public interface OrderItemDao {
	
	@Select("select * from product_order where orderId=#{orderId}")
	@Results({
		@Result(property="product",column="productId",one = @One(select="edu.gdut.tiantian.dao.ProductDao.findById")),
		@Result(property="buyNum",column="buyNum")
	})
	List<OrderItem> getOrderItem(String orderId);
	
	@Insert("insert into product_order(productId,orderId,buyNum) values(#{productId},#{orderId},#{buyNum})")
	void addToOrder(@Param("productId")String productId,@Param("orderId")String orderId,@Param("buyNum")int buyNum);
}
